<?
class Rule_Exists extends Rule
{
	public $table;
	public $error_message="Значение не существует";
	
	function __construct($name,$table, $error_message="")
	{
		$this->name=$name;
		$this->table=$table;
		if($error_message!="") $this->error_message = $error_message;
	}
	
	function Check($hash)
	{
		$count = DB::scalarSelect("select count(*) from {$this->table} where {$this->name} = ? ", $hash[$this->name] );
		if(  $count==0 ) return false;
		return true;
	}
}